﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;

using Wicresoft.Common;
using Wicresoft.Framework.Organization;
using JDEduTrain.Framework.Entity;
using JDEduTrain.Framework.Business;

public partial class Page_TrainDetailStatDetail : BaseAuthenticationPage
{
    public Guid MemberID
    {
        get
        {
            if (Request["MemberID"] != null)
                return new Guid(Request["MemberID"]);
            return Guid.Empty;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        this.UseTabber = true;
        if (!IsPostBack)
        {
            BindClassMember();
        }
    }

    protected DataTable DTUserPageList
    {
        get
        {
            if (ViewState["DTUserPageList"] != null)
            {
                return (DataTable)ViewState["DTUserPageList"];
            }
            return new DataTable();
        }
        set
        {
            ViewState["DTUserPageList"] = value;
        }
    }


    protected void BindClassMember()
    {
        DataTable dtDetail = BLTrain.GetTrainDetailByMemberID(MemberID);
        dtDetail.Columns.Add("DeptDisplayName");
        float yeartotalScore = 0;
        float totalScore = 0;
        foreach (DataRow dr in dtDetail.Rows)
        {
            if (!string.IsNullOrEmpty(dr["MainDepartmentID"].ToString()))
            {
                Department dept = OrganizationHelper.GetDepartmentInfo(new Guid(dr["MainDepartmentID"].ToString()));
                dr["DeptDisplayName"] = dept.DisplayName;
                if (dr["PassTime"].ToString().Equals(DateTime.Now.Year.ToString()))
                {
                    try
                    {
                        yeartotalScore += float.Parse(dr["Score"].ToString());
                    }
                    catch (Exception)
                    {
                    }
                }
                totalScore += float.Parse(dr["Score"].ToString());
            }
        }
        ltTitle.Text = DateTime.Now.Year.ToString() + "年度获得" + yeartotalScore + "学分；" + "迄今总共获得" + totalScore + "学分";
        ltTitleAll.Text = ltTitle.Text;
        int thisYearRecordCount = 0;
        int recordCount = 0;
        DataTable dtThisYear = BLTrain.GetTrainDetailByMemberID(dpPager.CurrentPageIndex, dpPager.PageSize, MemberID, MemberTrainDetail.SQLCOL_PASSTIME + " desc", ref thisYearRecordCount,true);
        dpPager.RecordCount = thisYearRecordCount;
        rptOrderInfo.DataSource = dtThisYear;
        rptOrderInfo.DataBind();

        DataTable dtAll = BLTrain.GetTrainDetailByMemberID(dpPagerAll.CurrentPageIndex, dpPagerAll.PageSize, MemberID, MemberTrainDetail.SQLCOL_PASSTIME + " desc", ref recordCount, false);
        dpPagerAll.RecordCount = recordCount;
        rptAll.DataSource = dtAll;
        rptAll.DataBind();

        
    }
    protected void dpPager_PreRender(object sender,EventArgs e)
    {
        BindClassMember();
    }
    protected void dpPagerAll_PreRender(object sender, EventArgs e)
    {
        BindClassMember();
    }

    protected void btnRefresh_Click(object sender, EventArgs e)
    {
        BindClassMember();
    }


}
